/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */

/*
 * Created on 10/07/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package br.ufmg.dees.insane.xyplot.xyplot_view.dialog;

import java.awt.Toolkit;

import br.ufmg.dees.insane.commons.view.ViewState;
import br.ufmg.dees.insane.xyplot.xyplot_controller.XYPlotController;
import br.ufmg.dees.insane.xyplot.xyplot_view.InterfaceXYPlot;
import br.ufmg.dees.insane.xyplot.xyplot_view.XYPlotView;
import br.ufmg.dees.insane.xyplot.xyplot_view.XYPlotViewState;

/**
 * @author  Samuel Silva Penna  TODO To change the template for this generated type comment go to  Window - Preferences - Java - Code Style - Code Templates
 */
public class AxisSettingsDialogs extends TabbedDialog {
	
	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;
	private InterfaceXYPlot parent;
	/**
	 * @uml.property  name="axsDialog"
	 * @uml.associationEnd  multiplicity="(0 -1)"
	 */
	public AxisDialog[] axsDialog;
	private XYPlotViewState state;
	    
	/**
	 * Constructor method, calling super with the especific title.
	 *
	 * @param parent The parent of the class.
	 * @see xyplot_view.Interface
	 */
	public AxisSettingsDialogs(InterfaceXYPlot parent, ViewState s) {
		this.parent = parent;
	    state = (XYPlotViewState)s;
	    axsDialog = new AxisDialog[state.getNumberOfAxisViewStates()];
	    int j=0;
	    for (int i = 0; i < state.getNumberOfAxisViewStates(); i++){
	    	axsDialog[i] = new AxisDialog("Axis",state.getNumberOfAxisViewStates());
	    	// set up the tabbs
	    	axsDialog[i].getAxisTitleField().setText(((XYPlotController)parent.getView().getController()).getModel().getAxis(i).getLabel());
	    	axsDialog[i].setAxisColor(state.getAxisState(i).getAxisColor());           
	        axsDialog[i].setPositionX(state.getAxisState(i).getTitleXCenter());
	    	axsDialog[i].setPositionY(state.getAxisState(i).getTitleYCenter());
	    	axsDialog[i].setAxisTitleColor(state.getAxisState(i).getAxisTitleColor());
	        axsDialog[i].setSizeFontAxisTitle(state.getAxisState(i).getTitleTextSize());
	    	axsDialog[i].setSizeFontAxisMarksText(state.getAxisState(i).getMarkTextSize());
	        axsDialog[i].setStep(((XYPlotController)parent.getView().getController()).getModel().getAxis(i).getMainMark());	        
	        //add the tabbs
	    	if(state.indexOf(state.getAxisState(i))==0){
	        	this.addTab("Axis X ", axsDialog[i].addAxisTable("Axis X "+":"));
	        }else if(state.indexOf(state.getAxisState(i))==1){
	        	this.addTab("Axis Y ", axsDialog[i].addAxisTable("Axis Y"+":"));
	        }else{
	        	this.addTab("Axis # "+(j+1), axsDialog[i].addAxisTable("Axis "+(i+1)+":"));
	        	j++;
	        }
	    	axsDialog[i].getTextMarksPlaceCombo().setSelectedIndex((byte)(state.getAxisState(i).getMarkTextPlace()-1));
	    	axsDialog[i].getTitleFontCombo().setSelectedItem(state.getAxisState(i).getTitleTextFont());
	        axsDialog[i].getTitleStyleCombo().setSelectedIndex(state.getAxisState(i).getTitleTextStyle());
	        axsDialog[i].getTextMarksFontCombo().setSelectedItem(state.getAxisState(i).getMarkTextFont());
	    	axsDialog[i].setCheckMarksOnOff(state.getAxisState(i).isMarksOn());        
	        if(axsDialog[i].getCheckMarksOnOff()){
	        	axsDialog[i].getMarksOn().setSelected(true);
	            axsDialog[i].getMarksOff().setSelected(false);
	        }else{
	        	axsDialog[i].getMarksOn().setSelected(false);
	            axsDialog[i].getMarksOff().setSelected(true);
	        }
	   }
    }
	    
	public int showDialog() {
		return super.showDialog(parent, "Axis Settings");
	}
	    
	/**
	 * This method is executed on OK button click.
	 *
	 */
	public void approvedPerform() {
		try {
			for (int i = 0; i < state.getNumberOfAxisViewStates(); i++){
				this.axsDialog[i].approvedPerform();
	        }
	        for (int i = 0; i < state.getNumberOfAxisViewStates(); i++){
	            ((XYPlotController)parent.getView().getController()).getModel().getAxis(i).setLabel(axsDialog[i].getAxisTitleField().getText());
	            state.getAxisState(i).setTitleTextFont((String)axsDialog[i].getTitleFontCombo().getSelectedItem());
	            state.getAxisState(i).setTitleTextSize((int)axsDialog[i].getAxisTitleSizeDecimalField().getValue());
	            state.getAxisState(i).setTitleTextStyle((byte)axsDialog[i].getTitleStyleCombo().getSelectedIndex());
	        	state.getAxisState(i).setTitleXCenter(axsDialog[i].getPositionXField().getValue());
	        	state.getAxisState(i).setTitleYCenter(axsDialog[i].getPositionYField().getValue());
	        	state.getAxisState(i).setAxisTitleColor(axsDialog[i].getAxisTitleColorField().getBackground());       
	            state.getAxisState(i).setMarkTextFont((String)axsDialog[i].getTextMarksFontCombo().getSelectedItem());
	        	state.getAxisState(i).setMarkTextSize((int)axsDialog[i].getTextMarksFontSize().getValue());
	        	state.getAxisState(i).setMarkTextStyle((byte)axsDialog[i].getTextMarksFontCombo().getSelectedIndex());
	        	state.getAxisState(i).setMarkTextPlace((byte)(axsDialog[i].getTextMarksPlaceCombo().getSelectedIndex()+1));
	        	((XYPlotController)parent.getView().getController()).getModel().getAxis(i).setMainMark(axsDialog[i].getStepField().getValue());
	        	state.getAxisState(i).setAxisColor(axsDialog[i].getAxisColorField().getBackground());       
	            state.getAxisState(i).setMarksOn(axsDialog[i].getMarksOn().isSelected());
	        }
	        this.setVisible(false);
	        ((XYPlotView)parent.getView()).getDrawingArea().repaint();
	      //  LastZoomCommand cmd = new LastZoomCommand(parent);
	     //   cmd.execute();
	     }catch (Exception err) {
	     	Toolkit.getDefaultToolkit().beep();
	        this.setVisible(false);
	     }
	}

}
